package com.ruoyix.flowable.controller;

import java.util.List;
import java.util.Arrays;

import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyix.common.annotation.RepeatSubmit;
import com.ruoyix.common.annotation.Log;
import com.ruoyix.common.core.controller.BaseController;
import com.ruoyix.common.core.domain.PageQuery;
import com.ruoyix.common.core.domain.R;
import com.ruoyix.common.core.validate.AddGroup;
import com.ruoyix.common.core.validate.EditGroup;
import com.ruoyix.common.enums.BusinessType;
import com.ruoyix.common.utils.poi.ExcelUtil;
import com.ruoyix.flowable.domain.vo.BpmTaskExtVo;
import com.ruoyix.flowable.domain.bo.BpmTaskExtBo;
import com.ruoyix.flowable.service.IBpmTaskExtService;
import com.ruoyix.common.core.page.TableDataInfo;

/**
 * 流程任务扩展
 *
 * @author ruoyi
 * @date 2023-11-30
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/flowable/bpmTaskExt")
public class BpmTaskExtController extends BaseController {

    private final IBpmTaskExtService iBpmTaskExtService;

    /**
     * 查询流程任务扩展列表
     */
    @SaCheckPermission("flowable:bpmTaskExt:list")
    @GetMapping("/list")
    public TableDataInfo<BpmTaskExtVo> list(BpmTaskExtBo bo, PageQuery pageQuery) {
        return iBpmTaskExtService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出流程任务扩展列表
     */
    @SaCheckPermission("flowable:bpmTaskExt:export")
    @Log(title = "流程任务扩展", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(BpmTaskExtBo bo, HttpServletResponse response) {
        List<BpmTaskExtVo> list = iBpmTaskExtService.queryList(bo);
        ExcelUtil.exportExcel(list, "流程任务扩展", BpmTaskExtVo.class, response);
    }

    /**
     * 获取流程任务扩展详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("flowable:bpmTaskExt:query")
    @GetMapping("/{id}")
    public R<BpmTaskExtVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable String id) {
        return R.ok(iBpmTaskExtService.queryById(id));
    }

    /**
     * 新增流程任务扩展
     */
    @SaCheckPermission("flowable:bpmTaskExt:add")
    @Log(title = "流程任务扩展", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody BpmTaskExtBo bo) {
        return toAjax(iBpmTaskExtService.insertByBo(bo));
    }

    /**
     * 修改流程任务扩展
     */
    @SaCheckPermission("flowable:bpmTaskExt:edit")
    @Log(title = "流程任务扩展", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody BpmTaskExtBo bo) {
        return toAjax(iBpmTaskExtService.updateByBo(bo));
    }

    /**
     * 删除流程任务扩展
     *
     * @param ids 主键串
     */
    @SaCheckPermission("flowable:bpmTaskExt:remove")
    @Log(title = "流程任务扩展", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable String[] ids) {
        return toAjax(iBpmTaskExtService.deleteWithValidByIds(Arrays.asList(ids), true));
    }
}
